from django.db import models


class BedType(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    type = models.CharField(db_column='type', max_length=20, verbose_name='房间类型', help_text='四人间/六人间')
    number = models.PositiveIntegerField(db_column='number', verbose_name='房间人数')

    def __str__(self):
        return '%s' % self.type

    class Meta:
        db_table = 'bed_type'
        verbose_name_plural = '床位类型'


class BuildManage(models.Model):
    SEX_CHOICES = (
        ('0', '女生寝室'),
        ('1', '男生寝室')
    )
    id = models.AutoField(db_column='id', primary_key=True)
    build_name = models.CharField(db_column='build_name', max_length=50, verbose_name='楼宇名称')
    number_of_floors = models.PositiveIntegerField(db_column='number_of_floors', verbose_name='楼层数量', default=6)
    number_of_room_per_floor = models.PositiveIntegerField(db_column='number_of_room_per_floor', verbose_name='每层房间数量',
                                                           default=20)
    bed_type = models.ForeignKey(
        BedType, models.DO_NOTHING,
        db_column='bed_type',
        related_name='bed_type_name',
        verbose_name='床位类型'
    )
    detail = models.CharField(max_length=1, choices=SEX_CHOICES, db_column='details', default='1', verbose_name='简介')

    def __str__(self):
        return '%s' % self.build_name

    class Meta:
        db_table = 'build_manage'
        verbose_name_plural = '楼宇管理'


class Room(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    name = models.CharField(db_column='name', max_length=30, verbose_name='房间号')
    number = models.IntegerField(db_column='number', verbose_name='床位数')
    bed_type = models.ForeignKey(
        BedType, models.DO_NOTHING,
        db_column='bed_type',
        related_name='bed_type',
        verbose_name='床位类型'
    )
    build_id = models.ForeignKey(BuildManage, models.CASCADE, db_column='build_id', verbose_name='楼宇名称', related_name='allRoom')
    actual_number = models.PositiveIntegerField(db_column='actual_number', verbose_name='实住人数', default=0)

    def __str__(self):
        return '%s' % self.name

    class Meta:
        db_table = 'room'
        verbose_name_plural = '房间管理'
